from django.db import models

from utils.BaseModel import BaseModel


# Create your models here.

class Department(BaseModel):
    name = models.CharField(max_length=32, verbose_name='科室名称')
    image = models.CharField(max_length=255, verbose_name='科室图片')
    parent = models.ForeignKey('self', on_delete=models.CASCADE, verbose_name='父级分类', null=True, blank=True,
                               related_name='son')

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'department'


class Hospital(BaseModel):
    name = models.CharField(max_length=32, verbose_name='医院名称')

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'hospital'


class Job(BaseModel):
    name = models.CharField(max_length=32, verbose_name='职称名称')

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'job'


class Area(models.Model):
    name = models.CharField(max_length=32, verbose_name='地区名称')
    parent = models.ForeignKey('self', on_delete=models.CASCADE, verbose_name='父级分类', null=True, blank=True,
                               related_name='son')

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'area'


class doctor(BaseModel):
    name = models.CharField(max_length=32, verbose_name='医生名称')
    image = models.CharField(max_length=255, verbose_name='医生图片')
    desc = models.TextField(verbose_name='医生简介')
    score = models.DecimalField(max_digits=3, decimal_places=1, verbose_name='医生评分')
    reply = models.IntegerField(verbose_name='医生回复数')
    price = models.IntegerField(verbose_name='医生价格')
    aid = models.ForeignKey(Area, on_delete=models.CASCADE, verbose_name='地区')
    jid = models.ForeignKey(Job, on_delete=models.CASCADE, verbose_name='职称')
    hid = models.ForeignKey(Hospital, on_delete=models.CASCADE, verbose_name='医院')
    did = models.ForeignKey(Department, on_delete=models.CASCADE, verbose_name='科室')

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'doctor'


class Question(BaseModel):
    content = models.TextField(verbose_name='问题内容')
    img = models.CharField(max_length=255, null=True, blank=True, verbose_name='问题图片')

    def __str__(self):
        return self.content

    class Meta:
        db_table = 'question'


class Patient(BaseModel):
    name = models.CharField(max_length=32, verbose_name='患者名称')
    sex = models.BooleanField(default=False, verbose_name='性别')
    birthday = models.DateField(default='2000-01-01', verbose_name='出生日期')
    weight = models.IntegerField(default=0, verbose_name='体重')
    liver = models.BooleanField(default=True, verbose_name='肝功能')
    kidney = models.BooleanField(default=True, verbose_name='肾功能')
    allergies = models.TextField(default='无', verbose_name='过敏史')
    disease = models.TextField(default='无', verbose_name='疾病史')
    pregnancy = models.TextField(default='无', verbose_name='是否怀孕')
    doctor = models.ForeignKey('doctor', on_delete=models.CASCADE, verbose_name='医生')
    user = models.ForeignKey('user.User', on_delete=models.CASCADE, verbose_name='用户')
    question = models.ForeignKey('Question', on_delete=models.CASCADE, verbose_name='问题')
    selected = models.BooleanField(default=False, verbose_name='是否选中')

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'patient'


class Comment(BaseModel):
    content = models.TextField(verbose_name='评论内容')
    score = models.IntegerField(verbose_name='评论评分')
    pid = models.ForeignKey('Patient', on_delete=models.CASCADE, verbose_name='患者')
    did = models.ForeignKey('doctor', on_delete=models.CASCADE, verbose_name='医生')

    def __str__(self):
        return self.content

    class Meta:
        db_table = 'comment'
